import React from 'react'
import QueueAnim from 'rc-queue-anim'
import PubSub from 'pubsub-js/src/pubsub'
import config from './../libs/config.js'

// animate js libs
import iio from '../libs/animatelib/iio.js'
import pokerutil from '../libs/animatelib/pokerutil.js'
import PokerIioController from '../libs/animatelib/game.js'

import '../styles/detail.scss'

export default class detail extends React.Component {
    constructor(props) {
        super(props)
    }
    componentDidMount() {
        var t = this;
        PubSub.publish('updateMenu','back')
        PubSub.publish('updateTitle','牌谱详情')
        var rowid = this.props.location.query.rowid
        iio.stop()
        $.ajax({
            url: config.server_host + '/api/rowdata?id=' + rowid,
            type: 'get',
            success: function(data) {
                if (data.code === 200) {
                    window.TimeControl = pokerutil.TimeControl
                    window.recordHelper = pokerutil.recordHelper
                    pokerutil.recordHelper.data = data.data;
                  	pokerutil.recordHelper.lang = "zh";
                    setTimeout(function() {
                        iio.start(PokerIioController,'pokerPanl');
                    },1)
                }
            }
        })
    }

    formatData =(data)=> {
        var users = data.match.table.seat;
        var me = users[data.userinfo.playerId];
        var seatAlias = {
            sb: parseInt(data.match.table.sb.number),
            bb: null,
            utg: null,
            ugt2: null,
            mp: null,
            mp2: null,
            hj: null,
            co: null,
            btn: null
        };
        data.match.table.seat.map(function(i) {
            switch (parseInt(i.seatNumber)) {
                case 1:
                    seatAlias.sb = i;
                    break;
                case 2:
                    seatAlias.sb = i;
                    break;
                case 3:
                    seatAlias.sb = i;
                break;
                case 4:
                    seatAlias.sb = i;
                break;
                case 5:
                seatAlias.sb = i;
                break;
                default:

            }
        })
    }

    handleClick = (e) => {

    }
    render() {
        return (
            <QueueAnim
            type={['bottom', 'top']}
            ease={['easeOutQuart', 'easeInOutQuart']}>
                <div className="ani-box" key="a">
                    <div className="pkl-detail">
                        <canvas id="pokerPanl" className="animatePanel" width="750px" height="560px"></canvas>
                    </div>
                </div>
            </QueueAnim>
        )
    }
}
